package com.doradance.app.home;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.doradance.R;
import com.doradance.account.utils.XCRoundRectImageView;
import com.doradance.entity.ActivityEntity;
import com.doradance.entity.IndexEntity;
import com.example.xlhratingbar_lib.XLHRatingBar;
import com.pachong.android.baseuicomponent.adapter.RecyclerViewBaseAdapter;
import com.pachong.android.frameworkbase.utils.EasyToast;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/2/22.
 */

public class HomeListAdapter extends RecyclerViewBaseAdapter<IndexEntity.RcmdCoursesBean> {

    public HomeListAdapter(Context con) {
        super(con);
    }

    @Override
    public RecyclerView.ViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        return new VH(setAdapterViewItem(parent, R.layout.home_recommend));
    }

    @Override
    public void onBindHolder(RecyclerView.ViewHolder viewHolder, int position) {
        VH holder = (VH) viewHolder;
        final IndexEntity.RcmdCoursesBean activityEntity = getData().get(position);
        holder.mTvRcmdTitle.setText(activityEntity.getName());
        holder.mTvRcmdFree.setText(activityEntity.getVip_name());
        holder.mTvRcmdTime.setText("训练周期:"+activityEntity.getCycle()+"小时");
        holder.mTvRcmdNum.setText(activityEntity.getLearning_count()+"人学过");
        holder.ratingbarId.setCountSelected(activityEntity.getDifficulty());
        Glide.with(getContext()).load(activityEntity.getCover()).asBitmap().dontAnimate()
                .placeholder(R.mipmap.init_logo).into(holder.mBgIvRcmd);
        holder.mBgIvRcmd.setAlpha(0.7f);
        holder.mIvCollectPlay.setAlpha(0.66f);
    }

    public class VH extends RecyclerView.ViewHolder {
        @Bind(R.id.bg_iv_rcmd)
        ImageView mBgIvRcmd;
        @Bind(R.id.tv_rcmd_title)
        TextView mTvRcmdTitle;
        @Bind(R.id.tv_rcmd_free)
        TextView mTvRcmdFree;
        @Bind(R.id.tv_rcmd_time)
        TextView mTvRcmdTime;
        @Bind(R.id.tv_rcmd_num)
        TextView mTvRcmdNum;
        @Bind(R.id.ratingbarId)
        XLHRatingBar ratingbarId;
        @Bind(R.id.iv_collect_play)
        ImageView mIvCollectPlay;
        public VH(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
